<!--
    by: yuanbiao 2021年06月10日
    name: x-pdf-viewer
    notes:
-->
<template>
  <div :id="id" :class="[`${prefixCls}`]"></div>
</template>

<script>
import pdfobject from 'pdfobject'
const prefixCls = 'x-pdf-viewer'

export default {
  name: 'x-pdf-viewer',
  props: {
    options: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data() {
    return {
      prefixCls: prefixCls,
      id: `xPdfViewer_${Math.random().toString().substring(2)}`
    }
  },
  mounted () {
    this.$nextTick(() => {
      pdfobject.embed(this.options.url || '', `#${this.id}`, {
        pdfOpenParams: {
          pagemode: 'thumbs',
          toolbar: 0,
          navpanes: 0,
          statesbar: 0,
          view: 'FitV',
          scrollbars: '0',
          ...(this.options.pdfOpenParams || {})
        }
      })
    })
  },
}
</script>
